<template>
    <div class="app-container">
      <Levelbar></Levelbar>
      <div class="main" v-loading = "loading">
            <div class="form-title">查看采购申请单</div>
            <el-form ref="form" :model="form" label-width="110px" class="form-pading">
                <aside>基础信息</aside>
                <el-row :gutter="21">
                    <el-col :span="5">
                        <el-form-item label="采购单号">
                            <span class="title-left">{{form.basisObj.flowNum || '--'}}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="5">
                        <el-form-item label="经销商">
                            <span class="title-left">{{form.basisObj.orguserName || '--'}}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="5">
                        <el-form-item label="手机号">
                            <span class="title-left">{{form.basisObj.phone || '--'}}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="5">
                        <el-form-item label="审核状态">
                            <span class="title-left">{{form.basisObj.secondCheck == 1 ? '复审通过' : form.basisObj.secondCheck == 2 ? '复审驳回' : '--'}}</span>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="21">
                    <el-col :span="7">
                        <el-form-item label="学校名称">
                            <span class="title-left">{{form.basisObj.schoolName}}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="14">
                        <el-form-item label="硬件开通情况">
                            <el-row :gutter="21">
                                <el-col :span="5">
                                    <span>e直播</span>
                                    <span v-if="form.basisObj.isElive == 1" class="onText">已开通</span>
                                    <span v-else class="offText">未开通</span>
                                </el-col>
                                <el-col :span="5">
                                    <span>空中课堂</span>
                                    <span v-if="form.basisObj.isAirclass == 1" class="onText">已开通</span>
                                    <span v-else class="offText">未开通</span>
                                </el-col>
                                <el-col :span="5">
                                    <span>报平安</span>
                                    <span v-if="form.basisObj.isPingan == 1" class="onText">已开通</span>
                                    <span v-else class="offText">未开通</span>
                                </el-col>
                                <el-col :span="5">
                                    <span>家校通</span>
                                    <span v-if="form.basisObj.isContact == 1" class="onText">已开通</span>
                                    <span v-else class="offText">未开通</span>
                                </el-col>
                            </el-row>
                        </el-form-item>
                    </el-col>
                </el-row>
                <aside>采购内容</aside>
                <div class="main-vip">
                    <el-row :gutter="21">
                        <el-col :span="2">
                            <span class="vipTitle">会员服务</span>
                        </el-col>
                        <el-col :span="4">
                            <el-form-item label="卡劵服务期限">
                                <span class="title-left">{{form.vipTable.month == 1 ? '月' : form.vipTable.month == 6 ? '半年' : form.vipTable.month == 12 ? '年' : '--'}}</span>
                            </el-form-item>
                        </el-col>
                        <el-col :span="4" v-if="form.vipTable.num">
                            <el-form-item label="采购数量">
                                <span class="title-left">{{form.vipTable.num}}</span>
                            </el-form-item>
                        </el-col>
                        <el-col :span="4" v-if="form.vipTable.unitPrice">
                            <el-form-item label="采购单价">
                                <span class="title-left">{{form.vipTable.unitPrice | moneySwitch}}</span>
                            </el-form-item>
                        </el-col>
                        <el-col :span="4" v-if="form.vipTable.price">
                            <el-form-item label="采购金额">
                                <span class="title-left">{{form.vipTable.price | moneySwitch}}</span>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </div>
               <div class="m-height" v-if="form.purchaseOn.length !== 0">
                    <b class="b-title">硬件服务    有折扣</b>
                    <el-row :gutter="20">
                        <el-col :span="15">
                            <table class='table' align="left">
                                <tr>
                                    <td align="center">卡券类型</td>
                                    <td align="center">卡券服务期限</td>
                                    <td align="center">采购单价</td>
                                    <td align="center">采购数量</td>
                                    <td align="center">小计</td>
                                </tr>
                                <tr v-for="item in form.purchaseOn" :key="item">
                                    <td align="center">{{fifter(item.serviceType)}}</td>
                                    <td align="center">{{item.month == 1 ? '月' : item.month == 6 ? '半年' : item.month == 12 ? '年' : '--'}}</td>
                                    <td align="center">{{item.unitPrice || '0.00'}}</td>
                                    <td align="center">{{item.num || '0'}}</td>
                                    <td align="center">{{item.price || '0.00'}}</td>
                                </tr>
                                <tr>
                                    <td align="center"></td>
                                    <td align="center"></td>
                                    <td align="center">合计</td>
                                    <td align="center" class="bold">{{form.purchaseOnObj.num}}</td>
                                    <td align="center" class="bold">{{form.purchaseOnObj.price | moneySwitch}}</td>
                                </tr>
                            </table>
                        </el-col>
                    </el-row>
                </div>
                <div class="m-height" v-if="form.purchaseOff.length !== 0">
                    <b class="b-title">硬件服务    无折扣</b>
                    <el-row :gutter="20">
                        <el-col :span="15">
                            <table class='table' align="left">
                                <tr>
                                    <td align="center">卡券类型</td>
                                    <td align="center">卡券服务期限</td>
                                    <td align="center">采购单价</td>
                                    <td align="center">采购数量</td>
                                    <td align="center">小计</td>
                                </tr>
                                <tr v-for="item in form.purchaseOff" :key="item">
                                    <td align="center">{{fifter(item.serviceType)}}</td>
                                    <td align="center">{{item.month == 1 ? '月' : item.month == 6 ? '半年' : item.month == 12 ? '年' : '--'}}</td>
                                    <td align="center">{{item.unitPrice || '0.00'}}</td>
                                    <td align="center">{{item.num || '0'}}</td>
                                    <td align="center">{{item.price || '0.00'}}</td>
                                </tr>
                                <tr>
                                    <td align="center"></td>
                                    <td align="center"></td>
                                    <td align="center">合计</td>
                                    <td align="center" class="bold">{{form.purchaseOffObj.num}}</td>
                                    <td align="center" class="bold">{{form.purchaseOffObj.price | moneySwitch}}</td>
                                </tr>
                            </table>
                        </el-col>
                    </el-row>
                </div>
                <aside>收款情况</aside>
                    <el-form-item label="原价总金额">
                        <span class="title-left">{{form.basisObj.originalMoney | moneySwitch}}</span>
                    </el-form-item>
                    <el-form-item label="应收金额">
                        <span class="title-left">{{form.basisObj.payableMoney | moneySwitch}}</span>
                    </el-form-item>
                    <el-form-item label="优惠后金额">
                        <span class="title-left">{{form.basisObj.money | moneySwitch}}</span>
                    </el-form-item>
                <aside>初审状态</aside>
                <!-- <el-row :gutter="21">
                    <el-col :span="7">
                        <el-form-item label="实收金额">
                            <span>{{form.basisObj.money | moneySwitch}}</span>
                        </el-form-item>
                    </el-col>
                </el-row> -->
                <el-form-item label="审核结果">
                    <span>{{form.basisObj.firstCheck == 1 ? '初审通过' : form.basisObj.firstCheck == 2 ? '初审驳回' : '--'}}</span>
                    <!-- <el-row :gutter="20" v-if="form.basisObj.firstCheck == 2">
                        <el-col :span="10">
                            <span style="margin-top:20px">{{form.basisObj.remark}}</span>
                        </el-col>
                    </el-row> -->
                </el-form-item>
                <aside>复审结果</aside>
                <el-form-item label="审核结果">
                    <span>{{form.basisObj.secondCheck == 1 ? '复审通过' : form.basisObj.secondCheck == 2 ? '复审驳回' : '--'}}</span>
                    <el-row :gutter="20" v-if="form.basisObj.secondCheck == 2">
                        <el-col :span="10">
                            <span style="margin-top:20px">{{form.basisObj.remark}}</span>
                        </el-col>
                    </el-row>
                </el-form-item>
            </el-form>
            <el-form label-width="100px" class = "form-pading">
            </el-form>
            <footer>
                <el-row type = "flex" class = "row-bg" justify = "center">
                    <el-col :span="2">
                        <el-button @click="go">返回</el-button>
                    </el-col>
                </el-row>
            </footer>
      </div>
  </div>
</template>
<script>
import Levelbar from '../../layout/Levelbar';
import {
  getPurchaseInfoDetail,
  getPurchaseInfo
} from 'api/serviceManage';
import { mapGetters } from 'vuex';
export default {
    name: 'cardView',
    components: { Levelbar },
    computed: {
        ...mapGetters(['uid'])
    },
    data() {
        return {
            textarea: '',
            radio: '1',
            rules: {
                sMoney: [
          { required: true, message: '内容不能为空' },
          { pattern: /^[0-9]\d*$/, message: '请输入正整数' }
                ]
            },
            pickerOptions: {
                disabledDate(time) {
                    return time.getTime() < Date.now() - 8.64e7;
                }
            },
            loading: false,
            form: {
                basisObj: {},
                purchaseOn: [],
                purchaseOnObj: {
                    num: '',
                    price: ''
                },
                purchaseOff: [],
                purchaseOffObj: {
                    num: '',
                    price: ''
                },
                vipTable: {}
            }
        };
    },
    created() {
        this.init();
    },
    methods: {
        init() {
            this.loading = true;
            getPurchaseInfo(this.$route.params.id)
        .then(data => {
            this.form.basisObj = data.data.content;
        })
        .then(() => {
            getPurchaseInfoDetail(this.$route.params.id).then(data => {
                this.loading = false;
                data.data.content.forEach((e, index) => {
                    if (e.serviceType == '123554') {
                        this.form.vipTable = e;
                    } else {
                        if (e.isFavorable == 1) {
                            this.form.purchaseOn.push(e);
                        } else {
                            this.form.purchaseOff.push(e);
                        }
                    }
                });
                // this.form.purchaseOnObj.num = this.form.purchaseOn.reduce((prev, curr) => {
                //     return curr.num + prev;
                // },0);
                // this.form.purchaseOnObj.price = this.form.purchaseOn.reduce((prev, curr) => {
                //     return ~~curr.price + prev;
                // },0);

                // this.form.purchaseOffObj.num = this.form.purchaseOff.reduce((prev, curr) => {
                //     return curr.num + prev;
                // },0);
                // this.form.purchaseOffObj.price = this.form.purchaseOff.reduce((prev, curr) => {
                //     return ~~curr.price + prev;
                // },0);
                this.form.purchaseOnObj.num = this.sum(this.form.purchaseOn,'num');
                this.form.purchaseOnObj.price = this.sum(this.form.purchaseOn,'price');
                this.form.purchaseOffObj.num = this.sum(this.form.purchaseOff,'num');
                this.form.purchaseOffObj.price = this.sum(this.form.purchaseOff,'price');
            });
        })
        .catch(() => {
            this.loading = false;
        });
        },
        sum(arr,val){
            //求和
            return arr.reduce((prev, curr) => {
                if(typeof curr[val] == 'string') return ~~curr[val] + prev;
                return curr[val] + prev;
            }, 0);
        },
        fifter(v) {
            switch (v) {
                case '123547':
                    return 'e直播';
                case '123552':
                    return '报平安';
                case '123551':
                    return '空中课堂';
                case '123553':
                    return '家校通';
                case '123554':
                    return '会员';
                default:
                    return '--';
            }
        },
        go() {
            this.$router.go(-1);
        }
    }
};
</script>
<style lang="scss" scoped>
.main-vip {
  border-bottom: 1px solid #dcdcdc;
  margin-bottom: 20px;
}
.vipTitle {
  text-align: right;
  vertical-align: middle;
  float: left;
  font-size: 14px;
  color: #666;
  width: 110px;
  line-height: 1;
  padding: 11px 12px 11px 0;
  box-sizing: border-box;
}
.onText {
  color: #666;
}
.b-title {
  font-size: 14px;
  margin-bottom: 15px;
  display: block;
}
.offText {
  color: #ff0000;
}
.m-height {
  overflow: hidden
}
.table {
  text-align: left;
  th,
  td {
    padding: 0 20px;
    width: 200px;
    height: 40px;
    font-size: 14px;
  }
  .bold {
    font-weight: bold;
  }
  //   tr:nth-child(2),
  //   tr:nth-child(3) {
  //     color: #666;
  //   }
  a {
    font-size: 15px;
    color: #ff5e2c;
  }
}
.title-left {
  margin-left: 10px;
}
.monty-icon {
  padding-left: 0 !important;
}
.el-icon-plus {
  color: #ff5e2c;
}
.title-icon {
  color: #999;
}
.title-center {
  text-align: center;
}
.title {
  padding-top: 30px;
  font-size: 20px;
}
footer {
  padding: 20px 0 40px;
}
i {
  cursor: pointer;
}
.main {
  padding: 0 50px;
  background: #fff;
  box-shadow: 0px 0px 5px 0px rgba(0, 0, 0, 0.1);
  -webkit-box-shadow: 0px 0px 5px 0px rgba(0, 0, 0, 0.1);
  .form-title {
    padding-top: 8px;
    text-align: center;
    font-size: 18px;
    color: #333;
    line-height: 72px;
    font-weight: bold;
    font-family: Microsoft YaHei;
    border-bottom: 1px solid #ddd;
  }
}
aside {
  position: relative;
  padding: 36px 0 0 20px;
  font-size: 14px;
  color: #333;
  margin-bottom: 40px;
  &::before {
    height: 14px;
    width: 4px;
    background: #ff5e2c;
    content: "";
    position: absolute;
    left: 0;
    bottom: 4px;
  }
}
input {
  -webkit-appearance: none;
  -moz-appearance: none;
  background-color: #fff;
  background-image: none;
  border-radius: 2px;
  border: 1px solid rgb(217, 200, 191);
  box-sizing: border-box;
  color: rgb(61, 41, 31);
  display: inline-block;
  font-size: inherit;
  height: 36px;
  line-height: 1;
  outline: none;
  padding: 3px 10px;
  transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
  width: 100%;

  &:focus {
    outline: none;
    border-color: #ff5e2c;
  }
}
</style>
